<?php
/**
 * oscshop2 B2C电子商务系统
 *
 * ==========================================================================
 * @link      http://www.oscshop.cn/
 * @copyright Copyright (c) 2015-2017 oscshop.cn. 
 * @license   http://www.oscshop.cn/license.html License
 * ==========================================================================
 *
 * @author    李梓钿
 *
 */
namespace osc\admin\model;
use think\Db;
class ArticleCategory{
	
	public function add($data){
		
		$validate = validate('ArticleCategory');
		if(!$validate->check($data)){
		    return ['error'=>$validate->getError()];
		}
		
		$category['image']=$data['image'];
		$category['pid']=$data['pid'];
		$category['name']=$data['name'];
		$category['meta_keyword']=$data['meta_keyword'];
		$category['meta_description']=$data['meta_description'];
		$category['update_time']=time();
		
		$cid=Db::name('ArticleCategory')->insert($category,false,true);
		
		if($cid){
			
			return true;
		}else{
			return false;
		}
		
	}
	
	public function edit($data){
		
		$validate = validate('ArticleCategory');
		
		if(!$validate->check($data)){
		    return ['error'=>$validate->getError()];
		}
		$cid=(int)$data['id'];
		
		$category['image']=$data['image'];
		$category['pid']=$data['pid'];
		$category['name']=$data['name'];
		$category['meta_keyword']=$data['meta_keyword'];
		$category['meta_description']=$data['meta_description'];
		$category['update_time']=time();
		
		$r=Db::name('ArticleCategory')->where('id',$cid)->update($category,false,true);
		
		if($r){
			
			return true;
		}else{
			return false;
		}
		
	}

	public function del_category($cid){			
			
			try{
									
				Db::name('ArticleCategory')->where('id',$cid)->delete();
				
				return true;
			}catch(Exception $e){
				return false;
			}
	}

	
}
?>